<?php
/**
 * It a especification o a table, it is a grid, with actions and header columns
 *
 * @author eduardo
 *
 */
class Grid extends HtmlTable
{
    public $id;

    function Grid($id, $columns, $list, $widths, $sleft='0', $top='0', $inc = null, $titleClass=NULL, $class=NULL)
    {
    	$this->id  = $id;
        $td        = null;

        //actions
        $td[-1][-1] = new td( 'Actions', 'Action', $titleClass );

        //create columns
        foreach ( $columns as $line => $info )
        {
            $td[-1][$info] = new td( $info, $info, $titleClass );
            $td[-1][$info]->setWidth( $widths[ $line ] );
            $td[-1][$info]->setHeight( $inc );
        }

        //title tr
        $tr[] = new tr($id.'trTitle', $td[-1]);

        if ( $list )
        {
            foreach ($list as $line => $info)
            {
                $value              = $info[0]; //id
                $remove[$line]      = new imagelink(null, 'admin/images/remove.png', 'index.php?remove'.$id.'='.$value);
                $edit[$line]        = new imagelink(null, 'admin/images/edit.png',   'index.php?edit'.$id.'='.$value);
                $td[$line]['-1']    = new td("remove$line", array( $edit[$line], $remove[$line] ), $class );

                //create a td for each columns for each line of data
                foreach ( $columns as $l => $i )
                {
                    $td[$line][$l] = new td( $line.$l, $info[$i], $class );
                    $td[$line][$l]->setHeight( $inc );
                }

                $tr[] = new tr("div$line", $td[$line] );
            }
        }

        parent::__construct($id,  $tr);

        if ( $sleft || $top )
        {
            $this->setPosition($sleft, $top);
        }
        else
        {
        	$this->setWidth( '100%' );
        }

        $this->setBorderCollapse( true );
    }
}


/**
* POG
*/
function getActionResult($id, $action='edit')
{
    return $_REQUEST[$action.$id];
}

?>
